import 'dart:ui';

import 'package:flutter/material.dart';

class CustomDrawer extends CustomPainter{
  List<DrawPoints> pointGroup;
  CustomDrawer(this.pointGroup);

  @override
  void paint(Canvas canvas, Size size) {
    for(final pointGroupItem in pointGroup){
      var paint = Paint()
        ..color = pointGroupItem.color
        ..strokeCap = StrokeCap.round
        ..strokeWidth = 10.0;
      if(pointGroupItem.points.length>1){
        for(int i=0;i<pointGroupItem.points.length-1;i++){
          if(i+1<pointGroupItem.points.length-1){
            Offset startP = pointGroupItem.points[i]!;
            Offset endP = pointGroupItem.points[i+1]!;
            canvas.drawLine(startP, endP, paint);
          }
        }
      }else if(pointGroupItem.points.isNotEmpty){
        canvas.drawPoints(PointMode.points, pointGroupItem.points.cast<Offset>(), paint);
      }
    }
  }
  @override
  bool shouldRepaint(covariant CustomDrawer oldDelegate) {
    return true;
  }
}

class DrawPoints {
  final List<Offset?> points;
  final Color color;
  DrawPoints({required this.points, this.color = Colors.black});
}